package com.example.myapplication.livedata.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.R;
import com.example.myapplication.databinding.FragmentLiveDataEnterBinding;

/**
 * A simple {@link Fragment} subclass.
 * create an instance of this fragment.
 */
public class LiveDataEnterFragment extends Fragment {


    FragmentLiveDataEnterBinding binding;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = FragmentLiveDataEnterBinding.inflate(getLayoutInflater());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initEvent();
    }

    private void initEvent() {
        binding.liveDataEnterMutableLiveData.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_liveDataEnterFragment_to_liveDataMutableLiveDataFragment));
        binding.liveDataEnterObservable.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_liveDataEnterFragment_to_liveDataObservableFragment));
        binding.liveDataEnterLifeCycle.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_liveDataEnterFragment_to_liveDataLifecycleFragment));
        binding.liveDataEnterViewModel.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_liveDataEnterFragment_to_liveDataViewModelFragment));

    }
}
